#!/bin/bash

disk=`fdisk -l|grep "Disk /dev"|awk '{print $2}'|sed 's/://g'|grep -v vda|sed 's/\/dev\///g'`
username=biyouxin
IP=`ifconfig |grep "Bcast"|awk '{print $2}'|awk -F: '{print $2}'|head -1`
##------------Function for format the disk------------##
function fdisk_mkfs()
{
fdisk -S 56 /dev/$disk << EOF
n
p
1
	
	
wq
EOF
sleep 5
mkfs.ext4 /dev/${disk}1
cat >>/etc/fstab <<EOF
`blkid /dev/${disk}1 | awk '{print $2}'|sed 's/\"//g' ` /data  ext4 noatime,nodiratime,acl,defaults 0 0
EOF
mkdir /data
mount -a
}

##------------Function Kernel youhua------------##
function ker_youhua()
{
cat  >>/etc/sysctl.conf << EOF
tcp_max_tw_buckets =200000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.conf.all.accept_redirects=0
EOF
}

##-----------Function the service off------------##
function service_off()
{
chkconfig blk-availability off
chkconfig ip6tables off
chkconfig iptables off
chkconfig iscsi off
chkconfig iscsid off
chkconfig netfs off
chkconfig postfix off
chkconfig udev-post off
chkconfig multipathd off
chkconfig netconsole off
chkconfig rdisc off
chkconfig restorecond off
chkconfig saslauthd off

}

##-------------------------------------------------------------##

#if [ ! $# == 1 ];then
#	echo "Usage:./${0} \$1"
#	echo "\$1 You can use command 'fdisk -l' check "
#	exit
#fi

echo "初始化硬盘"
fdisk_mkfs
yum install cronolog -y
#chkconfig nginx on

echo "系统优化"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
echo "*           soft     nofile    65535 " >> /etc/security/limits.conf
echo "*           hard     nofile    65535 " >> /etc/security/limits.conf
echo "*           soft     nofile    65535 " >> /etc/security/limits.d/90-nproc.conf
echo "*           hard     nofile    65535 " >> /etc/security/limits.d/90-nproc.conf
sed -i 's/*          soft    nproc     1024/*          soft    nproc     10240/g' /etc/security/limits.d/90-nproc.conf

ker_youhua
service_off
echo "*/30 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1" >>/var/spool/cron/root
#echo "0 3 * * * /bin/bash /data/scripts/checkdisk.sh" >>/var/spool/cron/root
#echo "0 0 * * * /bin/bash /data/scripts/nginx_log_cut.sh" >>/var/spool/cron/root



#系统安全审计
#logrotate日志保存周期
sed -i 's/weekly/monthly/g'  /etc/logrotate.conf
sed -i 's/rotate 4/rotate 72/g'  /etc/logrotate.conf
sed -i 's/#compress/compress/g'  /etc/logrotate.conf
service rsyslog restart

#开启审计功能
if [ `rpm -qa|grep audit|wc -l` -ne 0 ]
then
    yum install auditd -y
    service   auditd  start
else 
        service  auditd  start
fi

#设置服务器登录超时时间
cat >>/etc/profile<<EOF
TMOUT=600
source /etc/profile
EOF

#进程守护
#supervisor 安装
easy_install supervisor
wget https://gitee.com/zjkguo/ywjb/raw/master/soft/supervisord.conf -O /etc/supervisord.conf